﻿using SQLMap.Core;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Serialization;
/******************************************************************************************************************
* 
* 
* 说　明： SQLMap实例程序(版本：Version1.0.0)
* 作　者：李朝强
* 日　期：2015/05/19
* 修　改：
* 参　考：http://my.oschina.net/lichaoqiang/
* 备　注：暂无...
* 
* 
* ***************************************************************************************************************/
namespace SQLMAPApp
{

    /// <summary>
    /// 
    /// </summary>
    class Program
    {


        /// <summary>
        /// 入口程序
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Console.WriteLine("----------------------------SQLMap示例程序-----------------------------");
            //配置SQL-MAP
            SQLMap.Core.SqlMapConfig.Configure();

            //insert
            Insert();

            //query
            Query();

            //delete
            Delete();

            //update
            Update();

            Console.Read();
        }


        /// <summary>
        /// <![CDATA[新增操作]]>
        /// </summary>
        /// <returns></returns>
        static int Insert()
        {
            //dto
            SQLMap.Dto.sampe_article article = new SQLMap.Dto.sampe_article()
            {
                title = "法国部署十万军警",
                keywords = "法国",
                body = "法国部署十万军警",
                createBy = 1,
                modifyBy = 1,
                createOn = DateTime.Now,
                modifyOn = DateTime.Now
            };
            int iResult = DbHelper.ExcuteNonQuery("insert1", article);
            return iResult;
        }

        /// <summary>
        ///  <![CDATA[查询操作]]>
        /// </summary>
        /// <returns></returns>
        static DataSet Query()
        {
            //CommandInfor
            System.Data.DataSet ds = DbHelper.Query("select1");

            //循环Row
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                Console.WriteLine(string.Format("{0} {1}", ds.Tables[0].Rows[i][0], ds.Tables[0].Rows[i][1]));
            }
            return ds;
        }

        /// <summary>
        ///  <![CDATA[删除操作]]>
        /// </summary>
        /// <returns></returns>
        static int Delete()
        {
            //CommandInfor
            int iResult = DbHelper.ExcuteNonQuery("delete1", new { id = 1 });
            return iResult;
        }


        /// <summary>
        ///  <![CDATA[更新操作]]>
        /// </summary>
        /// <returns></returns>
        static int Update()
        {
            int iResult = DbHelper.ExcuteNonQuery("update1", new { id = 2, keywords = "军警" });
            return iResult;
        }


    }
}
